<template>
    <page-view>

        <el-card>
            <template #header>
                <div class="font-bold">菜品列表</div>
            </template>
            <el-form :model="queryFormData" :inline="true">
                <el-form-item label="用户昵称">
                    <el-input placeholder="请输入用户昵称" v-model="queryFormData.nickName" />
                </el-form-item>
               
                <el-form-item label="手机号码">
                    <el-input placeholder="请输入手机号码" v-model="queryFormData.phone" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="queryData" :loading="isLoading">
                        <el-icon>
                            <Search />
                        </el-icon>
                        查询
                    </el-button>
                </el-form-item>
            </el-form>

            <!-- 数据展示 -->
            <div v-loading="isLoading">
                <el-table :data="resultData.listData" border stripe height="800">
                  
                    <el-table-column label="ID" prop="id" width="70" align="center"></el-table-column>
                    <el-table-column label="昵称" prop="userInfo.nickName" align="center"></el-table-column>
                  
                 
                    <el-table-column label="手机号" prop="phone" align="center"></el-table-column>
                    <el-table-column label="地址" prop="address" align="center"></el-table-column>
                    <el-table-column label="联系人" prop="person_name" align="center"></el-table-column>

                    <el-table-column label="标签" prop="tag" align="center"></el-table-column>
                    <el-table-column label="操作" align="center">
                        <template #default="{row}">
                            <el-button type="danger" @click="delteCurrentItem(row.id)" :loading="isLoading">
                                <el-icon>
                                    <Delete />
                                </el-icon>
                                删除
                            </el-button>
                        </template>
                    </el-table-column>

                </el-table>
                <!-- 页码 -->

                <div class="flex flex-row justify-between items-center mt-10">

                    <div>当前{{ queryFormData.pageIndex }}页，
                        共{{ resultData.pageCount }}页，共{{ resultData.totalCount }}条
                    </div>
                    <el-pagination background layout="prev,pager,next" :total="resultData.totalCount"
                        @current-change="currentChange"></el-pagination>
                </div>
            </div>


        </el-card>
    </page-view>

</template>


<script setup>
import { reactive, inject, ref } from "vue";
import { Search,Delete } from "@element-plus/icons-vue"
import API from "../../utils/API";
import { ElNotification } from "element-plus";
import { onMounted, } from "vue";

const baseURL = inject("baseURL");
const queryFormData = reactive({
    nickName: "",
    pageIndex: 1,
    phone: "",
    
})
const isLoading = ref(false);
const resultData = reactive({
    listData: [],
    pageCount: 0,
    totalCount: 0

})
const queryData = () => {
    isLoading.value = true;
    API.addressInfo.getListByPage(queryFormData).then(result => {
        console.log(result);
        resultData.listData = result.listData;
        resultData.pageCount = result.pageCount;
        resultData.totalCount = result.totalCount;

    }).finally(() => {
        isLoading.value = false
    })
}
//删除
const delteCurrentItem = (id) => {
    API.addressInfo.deleteById(id).then(result=>{
        ElNotification({
            type: "seccess",
            title: "删除成功",
            message: "当前菜品删除成功"
        });
        queryData();
    }).catch(error=>{
        ElNotification({
            type: "danger",
            title: "删除失败",
            message: "当前菜品删除失败,请重试或联系管理员"
        });
    })
};
//页码发生变化
const currentChange = (index) => {
    queryFormData.pageIndex = index;
    queryData();
}


onMounted(() => {
    queryData()
})
</script>


<style>

</style>